/*************************************************************************
**
****************************************************************************/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui/QMainWindow>
#include "myhelper.h"
#include "MyAcsi.h"
#include "NsLink.h"
#include "DbFilter.h"
#include "login_dlg.h"
#include <QLabel>
#include <QTextEdit>
#include <QTreeView>
#include <QInputDialog>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QList>
#include <QPalette>
#include <QMap>
#include <QInputDialog>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QModelIndex>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QMovie>
#include <QTimer>
#include <QThread>
#include <QStringList>
#include "ccfgdlg.h"
#include "cmydatedlg.h"
#include "cdatasetdlg.h"
#include "clog.h"
#include <time.h>
#include <QDateTime>
#include "treeitem.h"
QT_BEGIN_NAMESPACE
class QAction;
class QListWidget;
class QMenu;
class QTextEdit;
class QSplitter;
class QTableWidget;
class QLabel;
class QTextEdit;
class QLineEdit;
class QGroupBox;
class QPushButton;
QT_END_NAMESPACE
#define  MAXClientNum 512
#define TIMEOUT_Associate 5
#define TIMEOUT_Associate1 1
struct Node
{
    int node_No;
    int node_Status;
};
//! [0]
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow();
protected:
    void contextMenuEvent(QContextMenuEvent *event);
private slots:
    void save();
    void login();
    void print();
    void undo();
    void about();
    void config();
    void closeClient();
    void on_tableViewPressed(const QModelIndex &);
    void on_treeViewPressed(QTreeWidgetItem *item ,int count);
    void checkItem(QTreeWidgetItem *item ,int count) ;
    void showWaitting();
    void btn1Exec();
    void btn2Exec();
    void btn3Exec();
    void btn4Exec();
    void btn5Exec();

    void onPressedMenu1();
    void onPressedMenu2();
    void onPressedMenu3();
    void onPressedMenu4();
    void onPressedMenu5();
    void onPressedMenu6();
    void onPressedMenu7();
    void onPressedMenu8();
    void onPressedMenu9();
    void onPressedMenu10();
    void onPressedMenu11();
    void onPressedMenu12();
    void onPressedMenu13();
    void onPressedMenu14();
    void onPressedMenu15();
    void onTreeMenu1();
    void onTreeMenu2();
    void onTreeMenu3();
    void onTreeMenu4();
    void onTreeMenu5();
    void onTreeMenu6();
    void onTreeMenu7();
    void onTreeMenu8();
    void onTreeMenu9();
    void onTreeMenu10();

    void onAutoClicked();
    void detectConnections();
    void dataSetDlg();
    void logDlg();
private:
    void initTreeView();
    void iniCentralWidget();
    void creatRightMenus();
    void createActions();
    void createMenus();
    void createToolBars();
    void createStatusBar();
    void createDockWindows();
    void setBtnNameandConnect();
    void tableMenu(const QModelIndex &pos);
    void treeMenu(QTreeWidgetItem *item );
    QString intToIpStr(const int ipVal);

    int myGetLogicDeviceDirectory(QString iedName, QString ldName);
    int myGetLogicNodeDirectory(QString iedName, QString lnName,int type);
    int myGetDataValues(QString iedName, QString lname);
    int myGetDataDirectory(QString iedName, QString lname);
    int myGetDataDefinition(QString iedName, QString lname);
    int mySetDataValue(int node,int type,QString ref);
    int createIedTree(QString Ied);
    bool isFc(QString str);
    bool isEqualItemChild(QString str,QTreeWidgetItem *item);
    void createMyTree(TreeItem *ptree,QTreeWidgetItem *item);
    QTextEdit *textEdit;
    QListWidget *customerList;
    QListWidget *paragraphsList;

    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *cfgMenu;
    QMenu *viewMenu;
    QMenu *helpMenu;

    QToolBar *fileToolBar;
    QToolBar *editToolBar;
    QToolBar *cfgToolBar;
    QAction *loadIedAct;
    QAction *saveAct;
    QAction *loginAct;
    //QAction *printAct;
    QAction *clearAct;
    QAction *aboutAct;
    QAction *aboutQtAct;
    QAction *quitAct;
    QAction *cfgAct;
    QAction *autoAct;
    QAction *associateAct;
    QAction *dataSetAct;
    QAction *logAct;

    QSplitter *pSplitter;
    QTableWidget *pTableView;
    QLabel *recvLabel;
    QTextEdit *pRecvTextEdit;
    /*
        QLabel *localhostLabel;
        QLabel *localportLabel;
        QLineEdit *localhostLineEdit;
        QLineEdit *localportLineEdit;
        QGroupBox *pGrpboxLocal;

        QPushButton *pConn;
        QPushButton *pStop;
        QPushButton *quitButton;
    */
    QGroupBox *pGrpFunc;
    QPushButton *pBtn1;
    QPushButton *pBtn2;
    QPushButton *pBtn3;
    QPushButton *pBtn4;
    //QPushButton *pBtn5;

    myHelper myhelp;
    FormHelper frhelp;
    bool isLoad;
    bool isLogin;
    CLinkDB LDB;
    CMyAcsi *ps[MAXClientNum];
    int curretRow;
    QModelIndex curretPos;
    QMap<QString, int> *mapIed;
    QMap<QString,Node> *pMap;
    QTreeWidget *pTreeView;
    QTreeWidgetItem *rootitem,*curretItem;
    QTimer *pTimer;
    TreeItem *myTree;
    QString logstr;
};
//! [0]

#endif
